//
//  MovieDetailTableViewCell.m
//  豆瓣电影
//
//  Created by dllo on 16/6/25.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "MovieDetailTableViewCell.h"
#import "MovieDetailModel.h"
#import "UIImageView+WebCache.h"
#import "GetHeightTools.h"


#define SIZE self.contentView.bounds.size

@interface MovieDetailTableViewCell()

@property (nonatomic, retain) UILabel *title;

@property (nonatomic, retain) UILabel *ratingName;

@property (nonatomic, retain) UILabel *rating;

@property (nonatomic, retain) UIImageView *posterView;

@property (nonatomic, retain) UILabel *rating_count;

@property (nonatomic, retain) UILabel *movieid;

@property (nonatomic, retain) UILabel *runting;

@property (nonatomic, retain) UILabel *genres;

@property (nonatomic, retain) UILabel *country;

@property (nonatomic, retain) UILabel *film_maker;

@property (nonatomic, retain) UILabel *actors;

@property (nonatomic, retain) UILabel *post_simple_;

@property (nonatomic, retain) UILabel *plot_simple;



@end

@implementation MovieDetailTableViewCell

-(void)dealloc
{
    [_ratingName release];
    [_movieDetailModel release];
    [_title release];
    [_rating release];
    [_posterView release];
    [_rating_count release];
    [_movieid release];
    [_runting release];
    [_genres release];
    [_country release];
    [_film_maker release];
    [_actors release];
    [_post_simple_ release];
    [_plot_simple release];
    [super dealloc];
}


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.title = [[UILabel alloc]init];
        [self.contentView addSubview:self.title];
        [self.title release];
        
        self.ratingName = [[UILabel alloc]init];
        self.ratingName.text = @"评分";
        [self.contentView addSubview:self.ratingName];
        [self.ratingName release];
        
        self.rating = [[UILabel alloc]init];
        [self.contentView addSubview:self.rating];
        [self.rating release];
        
        self.posterView = [[UIImageView alloc]init];
        [self.contentView addSubview:self.posterView];
        [self.posterView release];
        
        self.rating_count = [[UILabel alloc]init];
        [self.contentView addSubview:self.rating_count];
        [self.rating_count release];
        
        self.movieid = [[UILabel alloc]init];
        [self.contentView addSubview:self.movieid];
        [self.movieid release];
        
        self.runting = [[UILabel alloc]init];
        [self.contentView addSubview:self.runting];
        [self.runting release];
        
        self.genres = [[UILabel alloc]init];
        [self.contentView addSubview:self.genres];
        [self.genres release];
        
        self.country = [[UILabel alloc]init];
        [self.contentView addSubview:self.country];
        [self.country release];
        
        self.film_maker = [[UILabel alloc]init];
        self.film_maker.text = @"制作人";
        self.film_maker.font = [UIFont systemFontOfSize:25];
        [self.contentView addSubview:self.film_maker];
        [self.film_maker release];
        
        
        self.actors = [[UILabel alloc]init];
        self.actors.numberOfLines = 0;
        [self.contentView addSubview:self.actors];
        [self.actors release];
        
        self.post_simple_ = [[UILabel alloc]init];
        self.post_simple_.text = @"电影情节";
        self.post_simple_.font = [UIFont systemFontOfSize:25];
        [self.contentView addSubview:self.post_simple_];
        [self.post_simple_ release];
        
        self.plot_simple = [[UILabel alloc]init];
        self.plot_simple.numberOfLines = 0;
        [self.contentView addSubview:self.plot_simple];
        [self.plot_simple release];
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
  
    self.posterView.frame = CGRectMake(20, 20, SIZE.width / 3, SIZE.height / 3);
    
    //
    self.ratingName.frame = CGRectMake(SIZE.width / 3 + 50, 10, 80, self.posterView.frame.size.height / 5);
    
    self.movieid.frame = CGRectMake(SIZE.width / 3 + 50, self.posterView.frame.size.width / 5 + 15, SIZE.width / 3, self.posterView.frame.size.height / 5);
    
    self.runting.frame = CGRectMake(SIZE.width / 3 + 50, self.posterView.frame.size.width / 5 + 50, SIZE.width / 3, self.posterView.frame.size.height / 5);
    
    self.genres.frame = CGRectMake(SIZE.width / 3 + 50, self.posterView.frame.size.width / 5 + 85, SIZE.width / 3, self.posterView.frame.size.height / 5);
    
    self.country.frame = CGRectMake(SIZE.width / 3 +50, self.posterView.frame.size.width / 5 + 120, SIZE.width / 3, self.posterView.frame.size.height / 5);
    
    //
    self.film_maker.frame = CGRectMake(30, SIZE.height / 3 + 40, SIZE.width / 3 * 2, 30);
    
    CGFloat actorHeight = [GetHeightTools heightWithText:self.movieDetailModel.actors];
    self.actors.frame = CGRectMake(30, SIZE.height / 3 + 75, SIZE.width - 20, actorHeight);
    
    /**电影情节*/
    self.post_simple_.frame = CGRectMake(30, SIZE.height / 2 + 40, SIZE.width, 30);
    
    /**电影简述*/
    CGFloat plot_simple_height = [GetHeightTools heightWithText:self.movieDetailModel.plot_simple];
    self.plot_simple.frame = CGRectMake(10, SIZE.height / 3 * 2 - 30, SIZE.width - 10, plot_simple_height);
    
}


-(void)setMovieDetailModel:(MovieDetailModel *)movieDetailModel
{
    if (_movieDetailModel != movieDetailModel) {
        [_movieDetailModel release];
        _movieDetailModel = [movieDetailModel retain];
    }
    
    self.rating.text = movieDetailModel.rating;
    self.movieid.text = movieDetailModel.movieid;
    self.runting.text = movieDetailModel.runtime;
    self.genres.text = movieDetailModel.genres;
    self.country.text = movieDetailModel.country;
    self.actors.text = movieDetailModel.actors;
    self.plot_simple.text = movieDetailModel.plot_simple;

    
    NSURL *url = [NSURL URLWithString:movieDetailModel.poster];
    [self.posterView sd_setImageWithURL:url];

}

@end


























